package com.dzx.controller;

import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Random;
import java.util.concurrent.TimeUnit;

@RestController
public class TestController {

    @Value("${server.port}")
    String port;

    @GetMapping("/hi")
    public String home(@RequestParam String name) {
        return "hi " + name + ",i am from port:" + port;
    }

    @PostMapping("/hi2")
    public String home2(@RequestBody JSONObject jsonObject) throws InterruptedException {
        int l = new Random().nextInt(2000);
        TimeUnit.MILLISECONDS.sleep(l);
        return "hi " + jsonObject + ",i am from port:" + port;
    }

}

